<?php

namespace App\Http\Controllers\OpenShop\Feishu;

use App\Enums\OpenShop\InvestmentPromotion\UserContractEnum;
use App\Http\Controllers\BaseController;
use App\Models\Common\ConfigModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopContractTemplateModel;
use App\Remote\Feishu\Departments\DepartmentsRemote;
use App\Service\OpenShop\ContractTemplateService;
use App\Service\OpenShop\Feishu\FeishuApiService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Validation\ValidationException;

class ContractTemplateController extends BaseController
{

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function dataList(Request $request): JsonResponse
    {
        $mode         = (int)$request->get('mode', 0);
        $contractType = (int)$request->get('contractType', 0);
        $templateName = (string)$request->get('templateName', "");
        $pageSize     = (int)$request->get('pageSize', 10);
        $pageNum      = (int)$request->get('pageNum', 1);

        return $this->success(ContractTemplateService::dataList($contractType, $mode, $templateName, $pageSize, $pageNum));
    }


    /**
     * @throws GuzzleException
     */
    public function info(Request $request, int $id): JsonResponse
    {
        return $this->json(ContractTemplateService::info($id));
    }

    public function updateShow(Request $request, int $id): JsonResponse
    {
        $isShow = (int)$request->post('isShow', 0);
        $userId = request()->user()->id;

        return $this->json(ContractTemplateService::updateShow($id, $isShow, $userId));
    }


    /**
     * @throws GuzzleException
     * @throws ValidationException
     */
    public function getInstancesInfo(Request $request): JsonResponse
    {
        $instancesId  = (string)$request->post('instances_id', "");
        $appId  = (string)$request->post('app_id', "");

        $res = ContractTemplateService::getFeiShuCallbackInfo($appId,$instancesId);
        return $this->success(['showMsg'=>'','form'=>$res]);
    }
}